//
//  ChangePwdVC.swift
//  LeGou
//
//  Created by lxm on 2022/8/3.
//

import UIKit

class ChangePhoneOne: ZMViewController {

    //MARK:--------------------属性--------------------
    var phone = ""
    //MARK:--------------------UI控件--------------------
    @IBOutlet weak var titleLabel: UILabel!
    
    @IBOutlet weak var codeText: UITextField!
    
    //MARK:--------------------生命周期--------------------
    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
        addConstraints()
        bindAction()
    }
    //MARK:--------------------UI--------------------
    func setUI() {
        title = "修改手机号"
        titleLabel.text = "请输入\(phone.zm.hidPhone())收到的短信验证码"
        codeText.delegate = InputMananger.shard.onlyNumber
    }
    func addConstraints() {
        
    }
    
    //MARK:--------------------methods--------------------
    func bindAction() {
        
    }

    @IBAction func onCode(_ sender: CountButton) {
        LoginService.shared.showVerifycation(vc: self) { [unowned self] success in
            if success {
                LoginAPI.sendCode(["phone" : self.phone]).rxRequestNullAble(type: Any.self).subscribe(onNext:{ [unowned self] resp in
                    self.codeText.becomeFirstResponder()
                    sender.start(time: 60)
                }).disposed(by: self.disposeBag)
            }
        }
    }
    
    @IBAction func onNext(_ sender: Any) {
        guard let code = codeText.text, code != "" else {
            return ZMToast.showToast(title: "请输入验证码")
        }
        router.push("xm://main/Mine/set/change_phone_two")
    }
    
    //MARK:--------------------delegate--------------------

}
